const dayjs = require("dayjs");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    allNum: '',
    list: [],
    loading: true,
    pickerList1: [{
        id: 'all',
        name: '全部'
      },
      {
        id: 'rel_risk',
        name: '关联风险'
      },
      {
        id: 'opr_risk',
        name: '经营风险'
      },
      {
        id: 'credit_risk',
        name: '信用风险'
      },
      // {
      //   id: '',
      //   name: '橙色预警'
      // },
    ],
    pickerList2: [{
        id: 0,
        name: '全部'
      },
      {
        id: 7,
        name: '近7天'
      },
      {
        id: 30,
        name: '近30天'
      },
      {
        id: 182,
        name: '近半年'
      },
      {
        id: 365,
        name: '近一年'
      }
    ],
    selectList1: '全部',
    selectList2: '近7天',
    selectId1: '',
    selectId2: '7',
    serach_pro: '',
    showGz: false,
    companyId: '',
    listData: []
  },
  goSearch() {
    this.setData({
      list: [],
      allNum: ''
    })
    this.getList()
  },
  dealGuanzhu(e) {
    console.log(e.detail, '选择取消关注的公司id')
    this.setData({
      showGz: true,
      companyId: e.detail,
    });
  },
  async goQuxiao() {
    const params = {
      companyId: this.data.companyId,
    }
    console.log(params, '确定要取消关注的公司id')
    const res = await getApp().globalData.request(
      "/api/userApi/unsubscribeCompany",
      params,
      "POST"
    );
    console.log(res, '取消关注');
    this.getList()
  },
  onChange1(e) {
    console.log(e, 'eee')
    const id = +e.detail.value
    const obj = this.data.pickerList1[id]
    this.setData({
      selectList1: obj.name,
      selectId1: obj.id,
      list: []
    })
    // 重新查询
    this.getList()
  },
  onChange2(e) {
    const id = +e.detail.value
    const obj = this.data.pickerList2[id]
    this.setData({
      selectList2: obj.name,
      selectId2: obj.id,
      list: []
    })
    // 重新查询
    this.getList()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    // 更新时间区间划分
    // const maxTimer = dayjs().format('YYYY-MM-DD HH:mm:ss')
    // const timerList = [{
    //   id: 0,
    //   name: '全部'
    // },
    // {
    //   id: 1,
    //   name: '近7天',
    //   minTimer: '',
    //   maxTimer: maxTimer
    // },
    // {
    //   id: 2,
    //   name: '近30天',
    //   minTimer: dayjs().subtract(30, 'day').format('YYYY-MM-DD HH:mm:ss'),
    //   maxTimer: maxTimer
    // },
    // {
    //   id: 3,
    //   name: '近半年',
    //   minTimer: dayjs().subtract(182, 'day').format('YYYY-MM-DD HH:mm:ss'),
    //   maxTimer: maxTimer
    // },
    // {
    //   id: 4,
    //   name: '近一年',
    //   minTimer: dayjs().subtract(365, 'day').format('YYYY-MM-DD HH:mm:ss'),
    //   maxTimer: maxTimer
    // }]
    // this.setData({
    //   pickerList2: timerList
    // })
  },
  serachProChange(e) {
    this.setData({
      prolist: [],
      serach_pro: e.detail,
    });
    this.getList()
  },
  // 获取附近企业的坐标
  async getList() {
    const params = {
      

      corpName: this.data.serach_pro,
      riskType: this.data.selectId1 == 'all' ? '' : this.data.selectId1,
      recentDay: this.data.selectId2 == 0 ? '' : this.data.selectId2
    };
    this.setData({
      loading: true,
    });
    wx.showLoading({
      title: "加载中",
    });
    console.log(params, "查询条件33");
    const res = await getApp().globalData.request(
      // "/user/query_follow_corps",
      "/user/query_follow_corpsV2", {
        ...params
      },
      "POST"
    );
    console.log(res, 'res')
    this.setData({
      loading: false,
      listData: res
    });
    setTimeout(function () {
      wx.hideLoading();
    }, 800);
    // 原始列表数据
    if (res.data !== null) {
      this.setData({
        list: res.data.followStatisticList,
        allNum: res.data.totalRisk
      });
    } else {
      this.setData({
        list: [],
      });
    }
    // console.log(this.data.originList, "原始附近企业查询结果");
    // console.log(this.data.nearByList, "附近企业查询结果");
  },

  goDetail() {
    if (this.data.token) {
      const userInfo = JSON.stringify(this.data.userInfo);
      wx.navigateTo({
        url: `/pages/personalInfo/personalInfo?userInfo=${userInfo}`,
      });
    }
  },

  async toprodetail(e) {
    // console.log(this.data.selectList1,this.data.selectList2)
    const vipCode = await getApp().globalData.checkVipStatus()
    if (vipCode === 'ordinary' || vipCode === 'notVipBindFI' || vipCode === 'vipBindFI' || vipCode === 'bindGOV' || vipCode === 'visitor') {
      wx.showModal({
        title: '提示',
        content: '该功能为SVIP会员功能，请联系客服了解详情。',
        showCancel: false,
        confirmText: '确定',
        success: function () {}
      })
      return
    }
    wx.navigateTo({
      url: `/sub_monitor/detail/detail?corpCredit=${e.detail.credit}&name1=${e.detail.name1}&name2=${e.detail.name2}`,
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.goSearch()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {},
});